#include"tcp_server.hpp"
#include<unordered_map>
std::unordered_map<std::string,std::string> dict;

void Tranlate(std::string req,std::string* resp){
    std::cout<<req<<std::endl;
    auto it=dict.find(req);
    if(it==dict.end()){
        *resp="未找到这个词";
        return;
    }
    *resp=it->second;
    return;
}
int main(int argc,char* argv[])
{
    if(argc!=3){
        std::cout<<"Usage: ./server server_ip server_port\n";
        return 1;
    }
    dict.insert({"hello","你好"});
    dict.insert({"apple","苹果"});
    dict.insert({"banana","香蕉"});
    dict.insert({"orange","橘子"});
    std::string server_ip=argv[1];
    u_int16_t server_port=atoi(argv[2]);
    TcpServer server(server_ip,server_port);
    server.start(Tranlate);

    return 0;
}